/* === LICENSE INFO ===
 * This source file is subject to the GPLv3 license that is bundled with this
 * package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl.txt
 * === end of LICENSE INFO === */

/*==============================================================================
  File Name   : LogConfig.hpp
  Description : Declaration for LogConfig class in GLog module.

  Created on  : 2010-11-27
  Updated on  : 2011-01-30
  Updated by  : Lee Shiou Ming

  Cautions    : (important notes)
  ============================================================================*/

#ifndef LOGCONFIG_HPP_
#define LOGCONFIG_HPP_

#include "GLogDefinition.hpp"
#include <set>
#include <string>

#define MAX_LOG_FILE_SIZE_BYTE           4000000000u  // ~ 4GB

#define DEFAULT_MAX_LOG_LEVEL            LEVEL_NOTICE
#define DEFAULT_LOG_FILE_PATH            "GLog"
#define DEFAULT_LOG_OUTPUT_TYPE          OUTPUT_SCREEN
#define DEFAULT_LOG_ROTATION_SIZE_BYTE   1000000000u  // ~ 1GB
#define DEFAULT_LOG_ROTATION_INTERVAL    TIME_INTERVAL_DAILY

#define LOG_CFG_LOG_LEVEL            "config.max_log_level"
#define LOG_CFG_ENABLED_OUTPUT       "config.enabled_output"
#define LOG_CFG_LOG_FILE_PATH        "config.log_file_path"
#define LOG_CFG_ROTATION_CRITERIA    "config.log_file_rotation"
#define LOG_CFG_ROTATION_BY_SIZE_KB  "config.log_file_rotation.by_size_kilobyte"
#define LOG_CFG_ROTATION_BY_INTERVAL "config.log_file_rotation.by_interval"


/**
 * @brief All gUtil modules will be wrapped within gUtil namespace.
 */
namespace gUtil
{
/**
 * @brief Namespace for GLog module.
 */
namespace GLog
{
    /**
     * @brief Class that encapsulates implementation of logging configuration.
     *        Accessible by GLog class only.
     */
    class LogConfig
    {
    public:
        friend class GLog;

    private:
        /**
         * @brief Constructor with no parameter.
         */
        LogConfig();

        /**
         * @brief Interface for loading configuration from file into memory.
         *
         * @param _configFile
         * [IN] File path of the configuration file.
         * @param _configFileFormat
         * [IN] The format of the configuration file, default is XML.
         *
         * @return
         * - true ==> Succeed.
         * - false ==> Logger is already in configured state.
         */
        bool loadFromFile(const std::string& _configFile,
                const ConfigFileFormat _configFileFormat = CONFIG_FILE_XML);

        /**
         * @brief Flag that indicates if the logger instance has been
         *        configured.
         *
         * Becomes true during first invocation of getInstance(), or whenever
         * client invokes the initConfig(), whichever comes first.
         */
        bool m_isConfigured;

        /**
         * @brief Log entry with severity level higher than this max level will
         *        not be logged.
         */
        LogLevel m_maxLogLevel;

        /**
         * @brief List of enabled log output types.
         *
         * The log writer manager will create and manage a list of writers
         * corresponding to these output types.
         */
        std::set<LogOutputType> m_enabledOutputTypes;

        /**
         * @brief Path to log file, default value is "GLog".
         */
        std::string m_logFilePath;

        /**
         * @brief Maximum size of each log file in byte. This value cannot be
         *        greater than MAX_LOG_FILE_SIZE_BYTE (about 4GB).
         *
         * If the value is less than 1, the rotation size has to be set to
         * DEFAULT_LOG_ROTATION_SIZE_BYTE (about 1GB). If the value is greater
         * than max, the size will be set to MAX_LOG_FILE_SIZE_BYTE (about 4GB).
         */
        unsigned int m_logRotationSize;

        /**
         * @brief Time interval of log file rotation.
         */
        TimeInterval m_logRotationInterval;

    };  /* end of class LogConfig */

}  /* end of namespace GLog */
}  /* end of namespace gUtil */

#endif  /* LOGCONFIG_HPP_ */
